#-*- coding:UTF-8 -*-
import sys
import os
import io
from urllib import request

sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码

#浏览器登录后得到的cookie，也就是刚才复制的字符串
cookie_str = r'remember_82e5d2c56bdd0811318f0cf078b78bfc=eyJpdiI6IlozeU5scGlZUnBEb2hiSE16aUt4eEE9PSIsInZhbHVlIjoidkNcL0hKWWg3N000ano1cDIrVnRDRVlqU0xqM0JpXC9DN3d3M01yZnZkakl2M0Z5MFNjUUxVT1o3MDM0MmhYMFp6UjRZVFUwZFZnRXpuSjJ2cDhFVlVONHhid3pnb3Rlbm81Rmxjd2tGMzU4bz0iLCJtYWMiOiI4NTBjMzZmMWViYzY0ODM3NDhkMjJkODEzZGJjNmNjMTM0M2NkZmMxZTBiM2Q1ZjIxZjFiOTJiZDBmODZmZjVhIn0%3D; XSRF-TOKEN=eyJpdiI6Iktlc096V0ZPQlVDNXptR2FyNTlacVE9PSIsInZhbHVlIjoiZ1NTc0dxdDdTNFI1RWN1RDdUZ0Y4SjJ6XC9zdGg4NDdaVVVNNzJTQ1U1VnhBWEhZOEVFWnVDZGo0NEYrWjk4TVhHRzIwM1pPVno2NWV4REU2dXZxeGpBPT0iLCJtYWMiOiJmOTdkM2FlZmFjMDFlNWM3OTU4ZTA1ZmVhNzBlZWViY2QzNjYyNTVmYTcxNGQ4N2FkMDRmNjMwOWIxZjYzNTdiIn0%3D; laravel_session=eyJpdiI6IjlxOEJqM2dzUmp6bVpEZFJrOVM4V1E9PSIsInZhbHVlIjoiUk9yQUFcLzIrM2NkdEg0N2NJODFGQzRJeFd4WU43cmFpN3lLUEU1V1pXUkZEV01SeFNYMkRxS1FVWERibnFWS1Z1aHh2T1hmUzduSDBHSWJSWjZQVm1RPT0iLCJtYWMiOiI0NTg3YTRjNjk3YjU5MzA1MjI2OWFhZTVjNjAxZGI0OTVhNDEwODk0NTM5ZDU4OWQ1ZjI3MjIwNmU1YTQ1NTE1In0%3D'

# 登录后才能访问的网页
url = 'https://sns.totrial.com/profile/notification'

req = request.Request(url)
#设置cookie
req.add_header('cookie', cookie_str)
#设置请求头
req.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36')

resp = request.urlopen(req)
str = resp.read().decode('utf-8')
f = open("./dir0/file.txt", "w")

print(f.write(str))
